import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, map } from 'rxjs';
import { APPOINTMENT_BY_PHONE, APPOINTMENT_LIST, APPOINTMENT_TIMES, APPOINTMENT_TIMES2, APPOINTMENT_TYPE, BRANCH_COMPANY, COMPANY_HALL } from 'src/app/api/business/appointment';

@Injectable({
  providedIn: 'root'
})
export class AppointmentService {

  constructor(
    private http: HttpClient
  ) { }

  _getAppointmentLi(pageNumber: number = 1, pageSize: number = 5): Observable<any>{
    let args = {
      pageNumber,
      pageSize
    }
    let params = new HttpParams({ fromObject: args });

    return this.http.get(APPOINTMENT_LIST, { params });
  }

  // 取消预约
  cancelReservation(id: string): Observable<any>{
    let url = `/api/gsxmcp/cm/oa/v1.0/appointment/delete/${id}`;
    return this.http.post(url, null);
  }

  // 获取分公司
  _getBranchCompany(): Observable<any>{
    return this.http.get(BRANCH_COMPANY);
  }

  // 获取 营业大厅
  _getAppointmentHalls(id: string): Observable<any>{
    return this.http.get(COMPANY_HALL + id);
  }

  // 获取 预约业务类型
  _getAppointmentTypes(id: string): Observable<any>{
    return this.http.get(APPOINTMENT_TYPE + id);
  }

  // 获取 预约时段
  _getAppointmentTimes(id: string): Observable<any>{
    return this.http.get(APPOINTMENT_TIMES + id);
  }
  //判断时间段是否可预约
  _getAppointmentTime(hallId: string, typeId: string, date: string): Observable<any>{
    let args = {
      hallId,
      typeId,
      date
    }
    let params = new HttpParams({ fromObject: args });
    return this.http.get(APPOINTMENT_TIMES2, { params });
  }

  // 获取 预约详情
  getAppointmentDetail(id: string): Observable<any>{
    let url = `/api/gsxmcp/cm/oa/v1.0/appointment/detail/${id}`;
    return this.http.get(url);
  }

  // 提交预约
  _appointmentByPhone(params: any): Observable<any>{
    return this.http.post(APPOINTMENT_BY_PHONE, params);
  }
}

export type ReservationLiData = {
  appointmentId: string,
  hallAddressId: string,
  hallAddress: string,
  appointmentTypeName: string,
  appointmentTime: string,
  appointmentStateName: {},
  appointmentUserName: string,
  appointmentUserTel: string,
  appointmentCodeId: string
}
